#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
import UtilityFunctions

from VectorTestSequence import VectorTestSequence
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU


#  This test verifies that whole register move instructions are generated with
#  the operands aligned appropriately for the instruction.
class MainSequence(VectorTestSequence):
    def __init__(self, aGenThread, aName=None):
        super().__init__(aGenThread, aName)

        self._mInstrList = (
            "VMV1R.V##CALM",
            "VMV2R.V##CALM",
            "VMV4R.V##CALM",
            "VMV8R.V##CALM",
        )

    # Return a list of test instructions to randomly choose from.
    def _getInstructionList(self):
        return self._mInstrList

    # Verify additional aspects of the instruction generation and execution.
    #
    #  @param aInstr The name of the instruction.
    #  @param aInstrRecord A record of the generated instruction.
    def _performAdditionalVerification(self, aInstr, aInstrRecord):
        vd_val = aInstrRecord["Dests"]["vd"]
        vs2_val = aInstrRecord["Srcs"]["vs2"]
        align_mask = UtilityFunctions.getAlignMask(int(aInstr[3]))
        if ((vd_val & align_mask) != vd_val) or ((vs2_val & align_mask) != vs2_val):
            self.error("Instruction %s was generated with an improperly aligned operand" % aInstr)


MainSequenceClass = MainSequence
GenThreadClass = GenThreadGPGPU
EnvClass = EnvGPGPU
